@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

REM 设置颜色
set "RED=[91m"
set "GREEN=[92m"
set "YELLOW=[93m"
set "BLUE=[94m"
set "NC=[0m"

echo %GREEN%=== LikeAdmin Python 一键构建和上传脚本 ===%NC%
echo %YELLOW%此脚本将依次执行构建和上传操作%NC%
echo.

REM 获取参数
set "VERSION=%1"
set "SERVER_CONFIG=%2"

if "%VERSION%"=="" (
    echo %RED%错误: 请指定版本号%NC%
    echo %YELLOW%使用方法: build-and-upload.bat [版本号] [服务器地址]%NC%
    echo %YELLOW%示例: build-and-upload.bat v1.0.0 root@192.168.1.100:/opt/deploy%NC%
    pause
    exit /b 1
)

if "%SERVER_CONFIG%"=="" (
    echo %RED%错误: 请指定服务器地址%NC%
    echo %YELLOW%使用方法: build-and-upload.bat [版本号] [服务器地址]%NC%
    echo %YELLOW%示例: build-and-upload.bat v1.0.0 root@192.168.1.100:/opt/deploy%NC%
    pause
    exit /b 1
)

echo %BLUE%版本号: %VERSION%%NC%
echo %BLUE%服务器: %SERVER_CONFIG%%NC%
echo.

REM 确认操作
echo %YELLOW%确认执行以下操作？(Y/N)%NC%
echo %BLUE%  1. 构建Docker镜像并打包%NC%
echo %BLUE%  2. 上传文件到服务器%NC%
echo %BLUE%  3. 可选择自动部署%NC%
echo.
set /p "CONFIRM="
if /i not "%CONFIRM%"=="Y" (
    echo %YELLOW%操作已取消%NC%
    pause
    exit /b 1
)

echo %GREEN%=== 开始执行构建和上传流程 ===%NC%

REM 第一步：构建镜像
echo %YELLOW%第一步：构建Docker镜像...%NC%
call build-images-only.bat %VERSION%
if errorlevel 1 (
    echo %RED%镜像构建失败，停止执行%NC%
    pause
    exit /b 1
)
echo %GREEN%镜像构建完成%NC%

REM 第二步：上传文件
echo %YELLOW%第二步：上传文件到服务器...%NC%
call upload-only.bat %VERSION% %SERVER_CONFIG%
if errorlevel 1 (
    echo %RED%文件上传失败%NC%
    pause
    exit /b 1
)
echo %GREEN%文件上传完成%NC%

echo %GREEN%=== 构建和上传流程完成 ===%NC%
echo %BLUE%版本: %VERSION%%NC%
echo %BLUE%服务器: %SERVER_CONFIG%%NC%
echo %YELLOW%生成文件: likeadmin-python-%VERSION%.zip%NC%

pause 